//
//  KLStatusForwardCell.swift
//  BCWeiBo
//
//  Created by bcmac3 on 16/4/5.
//  Copyright © 2016年 KellenYangs. All rights reserved.
//

import UIKit

class KLStatusForwardCell: KLStatusTableViewCell {

    /// `重写`属性 didSet 不会覆盖父类的方法！子类只需要继续设置自己的相关内容即可！
    /// 需要和父类保持同样的行为
    override var status: KLStatus? {
        didSet {
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            
//            forwardLabel.text = "@" + name + ":" + text
            forwardLabel.attributedText = KLEmoticonPackage.emoticonString("@" + name + ":" + text, font: forwardLabel.font)
        }
    }
    
    override func setupUI() {
        super.setupUI()
        
        // 1. 添加控件
        // 插入背景到配图之下
        contentView.insertSubview(backButton, belowSubview: pictureView)
        // 插入文字道背景之上
        contentView.insertSubview(forwardLabel, aboveSubview: backButton)
        
        // 2. 设置布局
        // 设置正文布局
        contentLabel.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: 10, y: 10))
        
        // 背景按钮
        backButton.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -10, y: 10))
        backButton.xmg_AlignVertical(type: XMG_AlignType.TopRight, referView: footerView, size: nil)
        
        
        // 转发文本
        forwardLabel.xmg_AlignInner(type: XMG_AlignType.TopLeft, referView: backButton, size: nil, offset: CGPoint(x: 10, y: 10))
        
        // 配图
        let cons =  pictureView.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: forwardLabel, size: CGSizeZero, offset: CGPoint(x: 0, y: 10))
        widthCons = pictureView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Width)
        heightCons = pictureView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Height)
        topCons = pictureView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Top)
        
    }
    // MARK: - 懒加载控件
    /// 转发文字
    private lazy var forwardLabel: UILabel = {
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - CGFloat(2 * 10)
        return label
    }()
    
    /// 转发微博背景
    private lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return btn
    }()

}
